﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Web.UI;

using System.IO;
using System.Web.UI.HtmlControls;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Collection of <see cref="TabPanel"/>s.
	/// </summary>
	public class TabPanelCollection : ControlCollection<TabPanel>
	{
		/// <summary>
		/// Ctor.
		/// </summary>
		/// <param name="container"></param>
		public TabPanelCollection(TabContainer container):base(container._divMain)
		{
			this._container = container;
		}
		/// <summary>
		/// Gets the <see cref="TabContainer"/> which owns this collection.
		/// </summary>
		/// <remarks>
		/// The <see cref="ControlCollection<TabPanel>.Owner"/> will return <see cref="TabContainer._divMain"/>.
		/// </remarks>
		public TabContainer Container
		{
			get
			{
				return this._container;
			}
		}
		TabContainer _container;
		/// <summary>
		/// Called when a control is added.
		/// </summary>
		/// <param name="item"></param>
		protected override void OnItemAdded(TabPanel item)
		{
			base.OnItemAdded(item);

			item._container = this.Container;

			item._spanTab.Style[HtmlTextWriterStyle.Display] = item.Shown ? "inline-block" : "none";
			item._spanTab.Attributes["saveDisplay"] = "inline-block";
			item.Header.InstantiateIn(item._spanTab);
			this.Container._divHeader.Controls.Add(item._spanTab);
		}
	}
}